//============================================================================
//	Johns Hopkins University Whiting School of Engineering
//	605.461 Principles of Computer Graphics
//	Instructor:	David W. Nesbitt
//
//	Author:  David W. Nesbitt
//	File:    DrawLines.cpp
//	Purpose: OpenGL and GLUT program to draw line segments entered with 
//			   the mouse.  Line intersection calculation is also demonstrated.
//
//============================================================================

#include <iostream>
#include <vector>

#include <GL/gl3w.h>
#include <GL/glut.h>
#include "geometry/geometry.h"
#include "Scene/Color3.h"
#include "ShaderSupport/GLSLShader.h"

// Simple logging function
void logmsg(const char *message, ...)
{
   // Open file if not already opened
   static FILE *lfile = NULL;
   if (lfile == NULL)
      lfile = fopen("DrawLines.log", "w");

   va_list arg;
   va_start(arg, message);
   vfprintf(lfile, message, arg);
   putc('\n', lfile);
   fflush(lfile);
   va_end(arg);
}

/**
 * Reshape callback. Load a 2-D orthographic projection matrix using the 
 * window width and height so we can directly take window coordinates and 
 * send to OpenGL
 * @param  width  Window width
 * @param  height Window height
 */
void reshape(int width, int height)
{
   // Compute 2-D orthographic projection matrix
   Matrix4x4 orthoTransform;
   orthoTransform.m00() = 2.0f / (float)width;
   orthoTransform.m03() = -1.0f;
   orthoTransform.m11() = -2.0f / (float)height;
   orthoTransform.m13() = 1.0f;

   // Student TODO - make these available to the shaders

   // Update the viewport
   glViewport(0, 0, width, height);
}

/**
 * Main 
 */
int main(int argc, char** argv)
{
   std::cout << "Keyboard Controls:" << std::endl;
   std::cout << "  c - Clear all points" << std::endl;
   std::cout << "ESC - Exit program" << std::endl;

   return 0;
}